<template>
    <el-splitter>
        <el-splitter-panel size="50%" class="p-2">
            <div class="flex items-center mb-1">
                <span>AI引擎：</span>
                <AiProviderSelect v-model="provider"></AiProviderSelect>
                <el-link class="ms-2 text-xs" href="#" target="_blank">[打开官网]</el-link>
            </div>
            <el-input type="textarea" v-model="text" placeholder="请粘贴 AI 选号内容" :rows="20"></el-input>
            <el-button-group size="small">
                <el-button type="primary" @click="handleImport(text)">立即解析</el-button>
                <el-button type="warning" @click="text = ''">清空</el-button>
            </el-button-group>
        </el-splitter-panel>
        <el-splitter-panel :min="200" class="p-2">
            <div class="mb-2">
                <div>本期期号：{{ currentDrawNum }}</div>
                <div>上期开奖：{{ lastDrawInfo.lotteryDrawResult }}</div>
            </div>
            <div class="w-90">
                <div class="flex items-center pb-2 mb-3 border-b-1 border-b-solid border-gray-200">
                    <div class="w-5 text-end pr-2">#</div>
                    <div class="w-40">号码</div>
                    <div class="w-10 ml-2">和值</div>
                    <div class="w-20">操作</div>
                </div>
                <div class="h-83 overflow-y-auto" v-show="list.length > 0">
                    <div class="flex items-center mt-1" v-for="(item, idx) of list" :key="idx">
                        <div class="w-5 text-end pr-2">{{ idx + 1 }}</div>
                        <div class="w-40"><el-input size="small" clearable v-model="list[idx]" /></div>
                        <div class="w-10 ml-2">{{list[idx].split(' ').reduce((a, b) => parseInt(a) + parseInt(b))}}
                        </div>
                        <div class="w-20">
                            <el-button-group size="small">
                                <el-button type="danger" @click="onDeleteRow(idx)">删除</el-button>
                            </el-button-group>
                        </div>
                    </div>
                </div>
            </div>
            <el-empty v-show="list.length == 0">请点击【解析AI选号】按钮添加号码。</el-empty>
            <div class="text-xs text-gray-400 my-2">{{ stat.count }} 注 {{ stat.total }} 元</div>
            <div class="flex items-center justify-between">
                <el-button-group size="small">
                    <el-button type="danger" @click="list = []">清空</el-button>
                    <el-button type="info" @click="onCopy()">复制</el-button>
                    <el-button type="info" @click="onSave()">保存</el-button>
                </el-button-group>
            </div>
        </el-splitter-panel>
    </el-splitter>
</template>

<script setup>
import AiProviderSelect from '@/components/aiprovider-select/AiProviderSelect.vue';
import { ref } from 'vue';
import DltDataModel from '@/model/DltDataModel';
import DltOrderModel from '@/model/DltOrderModel';

let dltDataModel = new DltDataModel();
let dltOrderModel = new DltOrderModel();
const lastDrawInfo = dltDataModel.getLastRecord();
const currentDrawNum = parseInt(lastDrawInfo.lotteryDrawNum) + 1;
const provider = ref('DeepSeek');
const text = ref('');
const stat = ref({ count: 0, total: 0, });
const list = ref([]);
const aiList = ref({
    Nami: [],
    DeepSeek: [],
});

const handleImport = (text) => {
    list.value = dltOrderModel.parseAiText(text, provider.value.toLowerCase());
    aiList[provider.value] = list.value;
};
</script>